

# 150. 逆波兰表达式求值


def evalRPN(tokens):
    new_array = []
    new_array.append(int(tokens[0]))
    new_array.append(int(tokens[1]))
    for i in range(2, len(tokens)):
        if tokens[i] not in ['+', '-', '*', '/']:
            new_array.append(int(tokens[i]))
            print(new_array)
        else:
            two = new_array[len(new_array) - 1]
            one = new_array[len(new_array) - 2]
            del new_array[len(new_array) - 2:len(new_array)]
            if tokens[i] == '+':
                new_array.append(one + two)
                print("+",one + two)
                print(new_array)
            elif tokens[i] == '-':
                new_array.append(one - two)
                print("-", one - two)
                print(new_array)
            elif tokens[i] == '*':
                new_array.append(one * two)
                print("*", one * two)
                print(new_array)
            else:

                new_array.append(int(one / two))
                print("/", int(one / two))
                print(new_array)
    return new_array[0]

if __name__ == "__main__":
    result = evalRPN(["10","6","9","3","+","-11","*","/","*","17","+","5","+"])
    print(result)